{include file="header.html"}
<script type="text/javascript">
//<!CDATA[
$(function(){
    // multi-select mall_gcategory
    $('#gcategory').length>0 && gcategoryInit("gcategory");
});
//]]>
</script>
<div id="rightTop">
  <p>{$lang.goods}</p>
  <ul class="subnav">
    <li><!--{if $smarty.get.closed}--><a class="btn1" href="index.php?app=goods&act=iframe">{$lang.all_goods}</a><!--{else}--><span>{$lang.all_goods}</span><!--{/if}--></li>
    <li><!--{if $smarty.get.closed}--><span>{$lang.closed}</span><!--{else}--><a class="btn1" href="index.php?app=goods&act=iframe&amp;closed=1">{$lang.closed}</a><!--{/if}--></li>
  </ul>
</div>
<div class="mrightTop1 info">
  <div class="fontl">
    <form method="get" action="index.php?app=goods&act=iframe">
      <input type="hidden" name="app" value="goods" />
      <input type="hidden" name="act" value="iframe" />
      <!--{if $smarty.get.closed}-->
      <input type="hidden" name="closed" value="1" />
      <!--{/if}--> {$lang.goods_name}:
      <input class="queryInput" type="text" name="goods_name" value="{$smarty.get.goods_name|escape}" />
      {$lang.store_name}:
      <input class="queryInput" type="text" name="store_name" value="{$smarty.get.store_name|escape}" />
      {$lang.brand}:
      <input class="queryInput" type="text"  name="brand" value="{$smarty.get.brand|escape}" />
      {$lang.times}:
      <input class="queryInput" type="text" style="width: 300px;" name="times" value="{$smarty.get.times|escape}" placeholder="请用逗号分隔年代"/>
      {$lang.international_code	}:
      <input class="queryInput" style="width: 200px;" type="text" name="international_code" value="{$smarty.get.international_code|escape}" />
      <br/>
      <span style="position: relative; top: 5px;">
          {$lang.gcategory}:
          <div id="gcategory" style="display:inline;">
            <input type="hidden" name="cate_id" value="0" class="mls_id" />
            <select class="querySelect">
              <option>{$lang.select_pls}</option>
              {html_options options=$gcategories}
            </select>
          </div>
          仓库:
          <div id="storestock" style="display:inline;">
            <select class="querySelect" name="storestock_id">
              <option>{$lang.select_pls}</option>
              {html_options options=$storeStock selected=$storestock_id}
            </select>
          </div>
         {$lang.total_inventory}从:<input class="queryInput2" type="text" value="{$count_from}" name="count_from" />
                至:<input class="queryInput2" type="text" value="{$count_to}" name="count_to" class="pick_date" />
          商品价格从:<input class="queryInput2" type="text" value="{$price_from}" name="price_from" />
          至:<input class="queryInput2" type="text" value="{$price_to}" name="price_to" class="pick_date" />
            商品状态:
          <div style="display:inline;">
            <select class="querySelect" name="closed">
              <option value="">选择商品状态</option>
              <option value="1" <!--{if $closed eq 1}-->selected<!--{/if}-->>下架</option>
              <option value="2" <!--{if $closed eq 2}-->selected<!--{/if}-->>上架</option>
            </select>
          </div>
          <input type="submit" class="formbtn" value="{$lang.query}" />
          <input type="button" class="formbtn" value="关闭" id="btn-close"/>
          <input type="button" class="formbtn" value="选择" id="btn-choose"/>
      <!--{if $smarty.get.cate_id or $query.goods_name or $query.store_name or $query.brand}-->
      <a class="formbtn1" href="index.php?app=goods&act=iframe<!--{if $query.closed}-->&amp;closed={$query.closed}<!--{/if}-->">{$lang.cancel_query}</a>
      <!--{/if}-->
      </span>
    </form>
  </div>
  <div class="fontr">{include file=page.top.html}</div>
</div>
<div class="tdare">
  <table width="100%" cellspacing="0" class="dataTable">
    <!--{if $goods_list}-->
    <tr class="tatr1">
      <td width="5%" class="firstCell"><input type="checkbox" class="checkall" /></td>
      <td class="10%"><span ectype="order_by" fieldname="default_image">{$lang.default_image}</span></td>
      <td width="15%"><span ectype="order_by" fieldname="goods_name">{$lang.goods_name}</span></td>
      <td width="5%"><span ectype="order_by" fieldname="market_price">{$lang.market_price}</span></td>
      <td width="10%"><span ectype="order_by" fieldname="hong_kong_price">{$lang.hong_kong_price}|{$lang.discount}</span></td>
      <td width="10%"><span ectype="order_by" fieldname="domestic_price">{$lang.domestic_price}|{$lang.discount}</span></td>
      <td width="5%"><span ectype="order_by" fieldname="stock">{$lang.total_inventory}</span></td>
      <td><span ectype="order_by" fieldname="brand">{$lang.brand}</span></td>
      <td><span ectype="order_by" fieldname="cate_id">{$lang.gcategory}</span></td>
      <td width="10%"><span  fieldname="stock_name">{$lang.stock_name}</span></td>
      <td width="10%"><span  fieldname="stock_name">{$lang.times}</span></td>
      <td width="20%"><span  fieldname="international_code">{$lang.international_code}</span></td>
      <td class="table-center"><span ectype="order_by" fieldname="closed">{$lang.if_show}</span></td>
      <!--<td class="table-center"><span ectype="order_by" fieldname="closed">{$lang.close}</span></td>-->
      <td><span ectype="order_by" fieldname="views">{$lang.views}</span></td>
      <td>{$lang.handler}</td>
    </tr>
    <!--{/if}-->
    <!--{foreach from=$goods_list item=goods}-->
    <tr class="tatr2">
      <td class="firstCell"><input type="checkbox" attr-stock="{$goods.total_inventory}" attr-src="{$goods.default_image}"  attr-name="{$goods.goods_name}" attr-internationalcode="{$goods.international_code}" attr-stockname="{$goods.stock_name}"  attr-times="{$goods.times}" class="checkitem" value="{$goods.goods_id}"/></td>
      <td class="table-center"><img  height="100"  src="{$goods.default_image}" /></td>
      <td><span ectype="inline_edit" fieldname="goods_name" fieldid="{$goods.goods_id}" required="1" class="editable" title="{$lang.editable}">{$goods.goods_name|escape}</span></td>

      <td>{$goods.market_price|0.00}</td>
      <td>{$goods.hong_kong_price|0.00}|{$goods.hong_kong_discount}</td>
      <td>{$goods.domestic_price|0.00}|{$goods.domestic_discount}</td>
      <td>{$goods.total_inventory|escape}</td>
      <td>{$goods.brand|escape}</td>
      <td>{$goods.cate_name|nl2br}</td>
      <td>{$goods.stock_name}</td>
      <td>{$goods.times|escape}</td>
      <td>{$goods.international_code}</td>
      <!--<td class="table-center">&lt;!&ndash; {if $goods.if_show} &ndash;&gt;<img src="{res file=style/images/positive_enabled.gif}" />&lt;!&ndash;{else}&ndash;&gt;<img src="{res file=style/images/positive_disabled.gif}" />&lt;!&ndash; {/if} &ndash;&gt;</td>-->
      <!--<td class="table-center">&lt;!&ndash; {if $goods.closed} &ndash;&gt;<img src="{res file=style/images/negative_enabled.gif}" ectype="inline_edit" fieldname="closed" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/>&lt;!&ndash;{else}&ndash;&gt;<img src="{res file=style/images/negative_disabled.gif}" ectype="inline_edit" fieldname="closed" fieldid="{$goods.goods_id}" fieldvalue="0" title="{$lang.editable}"/>&lt;!&ndash; {/if} &ndash;&gt;</td> -->
      <td class="table-center"><!-- {if $goods.closed} -->下架<!--{else}-->上架<!-- {/if} --></td>
      <td>{$goods.views|default:0}</td>
      <td><a target="_blank" href="{$site_url}/index.php?app=goods&amp;id={$goods.goods_id}">{$lang.view}</a></td>
    </tr>
    <!--{foreachelse}-->
    <tr class="no_data info">
      <td colspan="8">{$lang.no_data}</td>
    </tr>
    <!--{/foreach}-->
  </table>
  <!--{if $goods_list}-->
  <div id="dataFuncs">
    <div class="pageLinks">{include file=page.bottom.html}</div>
   <!--{/if}-->
  </div>
  <div class="clear"></div>
</div>

<input id="goods_id" name="goods_id" style="display: none" value="{$banner.goods_id}">

{include file="footer.html"}
<script>

  $("#btn-close").click(function () {
      window.parent.$('.bg-model').hide();
  })
  $("#btn-choose").click(function () {
      var items = '';
      var name = '';
      var image = '';
      var stock = '';
      var internationalcode = '';
      var stockname = '';
      var times = '';

      //判断列表里是否有重复的数据
      var goods = window.parent.$("#goods_id").val();
      var goodsArr = goods.split(',');
      var result = 1;

      $('.checkitem:checked').each(function(){
          if ($.inArray(this.value, goodsArr) >= 0) {
              if(result == 1){
                  var truthBeTold = window.confirm("您选择的商品有重复项，继续添加会去除重复项！")
                  result = 2;
                  return true;
              }
          }else{
              items += this.value + ',';

              name += $(this).attr('attr-name') + ','
              image += $(this).attr('attr-src') + '^'
              stock += $(this).attr('attr-stock') + ','
              times += $(this).attr('attr-times') + ','
              internationalcode += $(this).attr('attr-internationalcode') + ','
              stockname += $(this).attr('attr-stockname') + ','
          }
      });
      items = items.substr(0, (items.length - 1));
      name = name.substr(0, (name.length - 1));
      stock = stock.substr(0, (stock.length - 1));
      image = image.substr(0,(image.length - 1));
      times = times.substr(0,(times.length - 1));
      internationalcode = internationalcode.substr(0, (internationalcode.length - 1));
      stockname = stockname.substr(0,(stockname.length - 1));

      var items_arr = items.split(',');

      var name_arr = name.split(',');
      var stock_arr = stock.split(',');
      var image_arr = image.split('^');
      var times_arr = times.split(',');
      var internationalcode = internationalcode.split(',');
      var stockname = stockname.split(',');

      if(!items){
          if(items_arr.length == 1){
              alert('该商品已存在列表中，请重新勾选商品！');
              return false;
          }
          alert('请勾选数据！');
          return false;
      }


      for(var i in items_arr){
          // window.parent.$(".choose_goods").append('<label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+name_arr[i]+'</label><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><img style="margin-right: 10px" src="templates/style/images/close.gif" onclick="dropGoods(this' +
          //     ')" fieldname="mall_recommended" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/>');


          window.parent.$("#after").after('' +
              '<tr class="tatr1">' +
              '<td width="15%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+name_arr[i]+'</label>' +
              '<td width="5%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+stock_arr[i]+'</label>' +
              '<td width="10%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+stockname[i]+'</label>' +
              '<td width="10%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+times_arr[i]+'">'+times_arr[i]+'</label>' +
              '<td width="30%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+internationalcode[i]+'">'+internationalcode[i]+'</label>' +
              '<td width="5%"><input style="width: 40px;" name="goodsSorts[]" type="text" class="infoTableInput2" value="9999" data-id="'+items_arr[i]+'"></td>'+
              '<td width="20%" class="table-center"><img  height="80" src="'+image_arr[i]+'" /></td>\n' +
          '<td width="20%" class="table-center"><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this' +
              ')" fieldname="mall_recommended" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/></td></tr>');
      }
      window.parent.$('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(',');
      window.parent.$('#goods_id').val(window.parent.$('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
      window.parent.$('.bg-model').hide();

  })


  function expEXCEL(url) {

  }

</script>